//
//  ZZWelcomeViewController.swift
//  web
//
//  Created by 张卓 on 2017/2/3.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

/*
    - 和控制器一样大小的背景图片
    - 用户头像
    - 用户文字
 
 */
class ZZWelcomeViewController: UIViewController {

    override func loadView() {
         view = bgImageView
    }
    
   
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        //设置动画  阻尼动画
        /*
            - withDuration 动画时长
            - delay 延迟时间
            - Damping 阻尼系数 (0 - 1 阻尼系数越小,弹性效果越好)
            - Velocity 起始速度
            - options 选项
         */
        UIView.animate(withDuration: 2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { ()->() in
            self.headImageView.snp_updateConstraints(closure: { (make) in
                make.top.equalTo(self.view).offset(100)
            })
            //强行刷新当前UI
            self.view.layoutIfNeeded()
        }, completion: { (_)->() in
            //动画完成以后
            UIView.animate(withDuration: 0.25, animations: {
                self.messageLabel.alpha = 1
            }, completion: { (_) in
                //发送通知,切换跟控制器  根控制器 为ZZMainVC
                NotificationCenter.default.post(name: NSNotification.Name(rawValue:SWITCHROOTVIEWCONTROLLERNOTI), object: "welcomeVC")
            })
        })
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setipUI()
        
    }
    
    //MARK: - 设置视图
    private func setipUI() {
        //01 添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        //02 添加约束
        headImageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
        }
        messageLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            make.centerX.equalTo(headImageView)
        }
        
    }
    
    
    //MARK: - 懒加载控件
    //背景图片
    private lazy var bgImageView : UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    //用户头像
    private lazy var headImageView : UIImageView = {
        let img = UIImageView(image: UIImage(named: "avatar_default"))
        //圆角
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        //边框
        img.layer.borderColor = ZZThemeColor.cgColor
        img.layer.borderWidth = 1
        //设置img
        
        
//        img.sd_setImage(with: URL(string: ZZOAuthViewModel.shared.userAccountModel?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default"))
        img.zz_setImage(urlString: ZZOAuthViewModel.shared.userAccountModel?.avatar_large)
        return img
    }()
    //文字上
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.text = "What the fuck day"
        //对齐
        lab.textAlignment = .center
        //透明度
        lab.alpha = 0
        return lab
    }()
    
    
    
    
    
}
